<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <base href="/">
    <title>添加学生</title>
    <script type="text/javascript" src="h-ui/lib/html5shiv.js"></script>
    <script type="text/javascript" src="h-ui/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/skin/red/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/css/style.css"/>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="addFrom" target="_parent">
        <div class="row cl">
            <label class="form-label col-xs-6 col-sm-4 text-r"> <span class="c-red">*</span>班&emsp;&emsp;级：
            </label>
            <div class="formControls col-xs-6 col-sm-6">
                <span class="select-box inline radius">
                <select class="select" name="classId" id="classId" onchange="classchang()">
                    <option value="">请选择班级</option>
                    <option th:each="list:${classlist}" th:value="${list.Cid}" th:text="${list.className }"></option>
                </select>
                </span>
                <span class="select-box inline radius">
                <select class="select" name="stu" id="stu">
                    <option value="">请选择学生</option>
                  <option th:each="list:${classlist}" th:value="${list.Cid}" th:text="${list.className }"></option>
                </select>
                </span>

            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-6 col-sm-4 text-r"> <span class="c-red">*</span>科目名称：
            </label>
            <div class="formControls col-xs-6 col-sm-6">
                <span class="select-box inline radius">
                <select class="select" name="kemu" id="kemu" onchange="kemuchack()">
                    <option value="">请选择科目</option>
                    <!--/*@thymesVar id="courseId" type="Long"*/-->
                    <option th:each="list:${courselist}" th:value="${list.courseId}" th:text="${list.courseName }"></option>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-6 col-sm-4 text-r"> <span class="c-red">*</span>分&emsp;&nbsp; 数：
            </label>
            <div class="col-sm-6">
                <input id="cj" name="cj" class="input-text radius" type="text" placeholder="请输入成绩"/>
            </div>
        </div>
        <!--        <input type="hidden" id="id" name="id" value="${leaveInfo.id}"/>-->
        <div class="row cl" style="text-algin: center;">
            <div class="col-6 col-offset-5">
                <input class="btn btn-success radius" type="submit" value="保存" id="save-btn">
                <button type="button" class="btn btn-secondary radius" onclick="window.location.reload();">取消</button>
            </div>
        </div>
    </form>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="h-ui/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="h-ui/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/jquery.form.min.js"></script>
<script type="text/javascript" src="h-ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="h-ui/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function () {
        $("#addFrom").validate({
            rules: {
                personName: {
                    required: true,
                    maxlength: 20,
                    remote: {
                        type: "post",
                        url: "person/checkname",
                        data: {
                            personName: function () {
                                return $("#personName").val();
                            }
                        }
                    }
                },
                mobile: {
                    required: true,
                    isMobile: true,
                    remote: {
                        type: "post",
                        url: "person/mobile",
                        data: {
                            mobile: function () {
                                return $("#mobile").val();
                            }
                        }
                    }
                },
                classId: {
                    required: true
                }
            },
            messages: {
                personName: {
                    required: "学生名不能为空",
                    maxlength: "名字过长",
                    remote: "学生已经存在"
                },
                mobile: {
                    required: "手机号码不能为空",
                    isMobile: "手机号码格式不正确",
                    remote: "手机号码已存在"
                },
                classId: {
                    required: "请选择班级"
                }
            },
            onkeyup: false,
            focusCleanup: false,
            success: "valid",
            submitHandler: function () {
                fromSubmit();
            }
        });

    });
    function kemuchack() {

        if ($("#kemu").val()) {
            $.ajax({
                url : "result/chackkm",
                type : "post",
                data : {
                    "classId" : $("#classId").val(),
                    "stu" : $("#stu").val(),
                    "kemu" : $("#kemu").val(),
                },
                async : true,
                dataType : "json",
                success : function(data) {
                    if(data.code){

                    }else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            });
        }
    }
    function classchang() {
        $("#stu").empty();
        if ($("#classId").val()) {
            $.ajax({
                url : "result/getStuList",
                type : "post",
                data : {
                    "classId" : $("#classId").val()
                },
                async : true,
                dataType : "json",
                success : function(data) {
                    console.log(data)
                    $("#stu").append('<option value="" selected>全部学生</option>');
                    $.each(data, function(i, item) {
                        $("#stu").append('<option value=' + item.personId + '>' + item.personName + '</option>');
                    });
                }
            });
        }
    }
    /*
        function chackname() {
            $.ajax({
                    type: "post",
                    url: "persson/checkname",
                    async: false,
                    data: {"personName": $("studentName").val(),},
                    success: function (data) {
                        console.log(data)
                    }
                }
            );

        }*/

    // 提交保存
    $("#save-btn").click(function () {
        $("#addFrom").submit();
    })

    function fromSubmit() {
        $('#save-btn').attr("disabled", "disabled");
        $("#addFrom").ajaxSubmit({
            url: "person/insertstudent",
            type: "post",
            dataType: "json",
            success: function (result) {
                if (result.sucess) {
                    layer.msg(result.msg, {
                        icon: 1,//提示的样式
                        time: 2000,
                        end: function () {
                            parent.location.reload()
                            layer_close();
                            // 刷新父页面列表并关闭编辑窗口
                            // layer_close();
                            // parent.table.ajax.reload();
                            // refreshParentAndClose(window.parent.rctable);
                        }
                    });
                } else {
                    $('#save-btn').removeAttr("disabled");
                    layer.msg(result.msg, {
                        icon: 2,
                        time: 2000
                    });
                }
            }
        });
    }
</script>
</body>
</html>